<?php

namespace app\api\controller\v1;

use app\common\controller\Api;
use app\common\model\video\Cate;
use app\common\model\video\Item;


/**
 * 会员接口
 */
class Video extends Api
{
    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';

    public function _initialize()
    {
        parent::_initialize();
    }


    /**
     * 视频分类
     */
    public function getCate() {
        $cate = Cate::all(function($query){
            $query->order('weigh', 'desc');
        });

        $this->success('cate', $cate);
    }

    /**
     * 视频列表
     */
    public function getList() {
        $cate_id = input('cate_id/d', 0);
        if (!$cate_id) {
            $this->error('参数错误');
        }

        $list = Item::where([
            'cate_id' => $cate_id,
            'switch' => 1
        ])->order('createtime desc')->paginate(15);

        $this->success('视频列表', $list);
    }
    public function search() {

        $search = input('keyword/s', '');
        $where = [];
        if ($search) {
            $where['name'] = ['like', "%$search%"];
        }

        $list = Item::where($where)
            ->field('content', true)

            ->order('createtime desc')->paginate(15);

        $this->success('视频列表', $list);

    }

    public function detail() {
        $id = input('id/d', 0);
        $detail = Item::get($id);
        if (!$detail) {
            $this->error('参数错误');
        }

        $this->success('detail', $detail);
    }
}
